package cn.tedu.jxc.controller;

import cn.tedu.jxc.pojo.dto.ProductSalesAddNewDTO;
import cn.tedu.jxc.pojo.vo.ProductListItemVO;
import cn.tedu.jxc.pojo.vo.SalesOrderListVO;
import cn.tedu.jxc.pojo.vo.UserSalesVO;
import cn.tedu.jxc.service.ProductSalesService;
import cn.tedu.jxc.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 销售单类
 */
@Slf4j
@Api(tags = "04. 销售单类")
@Validated
@RestController
@RequestMapping("/sales")
public class SalesController {
    @Autowired
    private ProductSalesService productSalesService;

    @ApiOperation("添加销售单")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> salesAdd(ProductSalesAddNewDTO productSalesAddNewDTO){
        log.debug("开始处理[添加销售单]的请求,参数:{}", productSalesAddNewDTO);
        productSalesService.salesAdd(productSalesAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("查询业务员名字列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("/select")
    public JsonResult<List<UserSalesVO>> selectUserNameList(){
        log.debug("开始处理[查询业务员名字列表]的请求,无参数");
        List<UserSalesVO> userSalesVOS = productSalesService.selectUserNameList();
        return JsonResult.ok(userSalesVOS);
    }

    @ApiOperation("查询销售单列表")
    @ApiOperationSupport(order = 410)
    @GetMapping("/selectSalesOrderList")
    public JsonResult<List<SalesOrderListVO>> selectSalesOrderList(){
        log.debug("开始处理[查询销售单列表]的请求,无参数");
        List<SalesOrderListVO> salesOrderListVOS = productSalesService.selectSalesOrderList();
        return JsonResult.ok(salesOrderListVOS);
    }

}
